import { createApp } from 'vue'

import Cookies from 'js-cookie'

import ElementPlus from 'element-plus'
import locale from 'element-plus/lib/locale/lang/zh-cn' // 中文语言

import '@/assets/styles/index.scss' // global css
import '@/assets/styles/custom.scss'
// element css
import 'element-plus/es/components/message/style/css'
import 'element-plus/es/components/message-box/style/css'
import 'element-plus/es/components/notification/style/css'
import 'element-plus/es/components/loading/style/css'
// tailwindcss
import './index.css'

// @ts-ignore
import App from './App'
import store from './store'
import router from './router'
import directive from './directive' // directive

// 注册指令
import plugins from './plugins' // plugins
import { download } from '@/utils/request'
import { downLoadByUrl, downLoadZip } from '@/utils/download.js'
import { useReturn } from '@/hooks/setting/useReturn'

// svg图标
import 'virtual:svg-icons-register'
//@ts-ignore
import SvgIcon from '@/components/SvgIcon'
import elementIcons from '@/components/SvgIcon/svgicon'
import '@/assets/font_icon/iconfont.css'

import './permission' // permission control

import { useDict } from '@/utils/dict'

import {
  parseTime,
  resetForm,
  addDateRange,
  handleTree,
  selectDictLabel,
  selectDictLabels
} from '@/utils/ruoyi'
import { deepClone } from '@/utils'

// 获取components组件
import commonComponents from '@/components'
// 获取业务组件
import businessComponents from '@/businessComponents'
// 首页组件
import homepageComponents from '@/views/dashboard/module'
//阿里图标的css
import './assets/icon/iconfont.css'

//研发管理-项目管理图标
import './assets/pro-icon/iconfont.css'

import 'uno.css'

import Avue from '@smallwei/avue'
import '@smallwei/avue/lib/index.css'

import print from 'vue3-print-nb'
// bpmn
import '@/components/bpmnProcessDesigner/package/theme/index.scss'
import 'bpmn-js/dist/assets/diagram-js.css'
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn.css'
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-codes.css'
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css'
import hljs from 'highlight.js' //导入代码高亮文件
import 'highlight.js/styles/github.css' //导入代码高亮样式  新版
import { dayjs } from 'element-plus'

dayjs.en.weekStart = 1
const app = createApp(App)
app.use(Avue)
//@ts-ignore
app.use(commonComponents)
app.use(businessComponents)
app.use(homepageComponents)
//自定义一个代码高亮指令
app.directive('highlight', function (el) {
  const blocks = el.querySelectorAll('code')
  blocks.forEach(block => {
    hljs.highlightElement(block)
  })
})

// 全局方法挂载
app.config.globalProperties.useReturn = useReturn
app.config.globalProperties.useDict = useDict
app.config.globalProperties.download = download
app.config.globalProperties.parseTime = parseTime
app.config.globalProperties.resetForm = resetForm
app.config.globalProperties.handleTree = handleTree
app.config.globalProperties.addDateRange = addDateRange
app.config.globalProperties.selectDictLabel = selectDictLabel
app.config.globalProperties.selectDictLabels = selectDictLabels
app.config.globalProperties.downLoadByUrl = downLoadByUrl
app.config.globalProperties.downLoadZip = downLoadZip
app.config.globalProperties.deepClone = deepClone
// 全局组件挂载
// app.component('DictTag', DictTag)
// app.component('Pagination', Pagination)
// app.component('TreeSelect', TreeSelect)
// app.component('FileUpload', FileUpload)
// app.component('ImageUpload', ImageUpload)
// app.component('ImagePreview', ImagePreview)
// app.component('RightToolbar', RightToolbar)

// 捕获错误信息
// app.config.errorHandler = function (err, vm, info) {
//   console.info('实例：', vm)
//   console.info('捕获到一个错误：' + err)
//   console.info('错误信息：' + info)
// }

app.use(store)
app.use(router)
app.use(plugins)
app.use(elementIcons)
app.component('svg-icon', SvgIcon)
app.use(print)

directive(app)

// 使用element-plus 并且设置全局的大小
app.use(ElementPlus, {
  locale: locale,
  // 支持 large、default、small
  size: Cookies.get('size') || 'default'
})

app.mount('#app')
